/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.madmac.encoding;

import java.io.UnsupportedEncodingException;

/**
 *
 * @author suporte
 */
public class Encoding {

	private static Encoding instance;
	
	private Encoding () {
		
	}
	
	public static Encoding getInstance () {
		
		if (instance == null) {
			instance = new Encoding();
		}
		
		return instance;
	}
	
	public String toUTF8 (String isoString) throws UnsupportedEncodingException {
		
		String utf8String = null;
		
		if (isoString != null && !isoString.equals("")) {
			try {
				
				byte[] stringByteISO = isoString.getBytes("ISO-8859-1");
				utf8String = new String (stringByteISO, "UTF-8");
				
			} catch (UnsupportedEncodingException e) {
				utf8String = isoString;
				throw new UnsupportedEncodingException("Não foi possível converter a palavra de ISO-859-1 para UTF-8");
			}
		} else {
			utf8String = isoString;
		}
		
		return utf8String;
	}
}
